// 输入框当子元素获取焦点时改变父元素的样式
$('.body>.body_2>div>.input1').focus(function(){
	$('.body_2>.diyigeshurukuang').addClass("cur");
	$('.body_2>.diyigeshurukuang>.l').addClass("cur1");
	$('.body_2>.diyigeshurukuang>.o').addClass("cur2");
	$('.body_1').addClass("cur3");
})
$('.body>.body_2>div>.input1').blur(function(){
	$('.body_2>.diyigeshurukuang').removeClass("cur");
	$('.body_2>.diyigeshurukuang>.l').removeClass("cur1");
	$('.body_2>.diyigeshurukuang>.o').removeClass("cur2");
	$('.body_1').removeClass("cur3");
})
$('.body>.body_2>div>.input2').focus(function(){
	$('.body_2>.diyigeshurukuang2').addClass("cur");
	$('.body_2>.diyigeshurukuang2>.l').addClass("cur1");
	$('.body_2>.diyigeshurukuang2>.o').addClass("cur2");
	$('.body_1').addClass("cur3");
})
$('.body>.body_2>div>.input2').blur(function(){
	$('.body_2>.diyigeshurukuang2').removeClass("cur");
	$('.body_2>.diyigeshurukuang2>.l').removeClass("cur1");
	$('.body_2>.diyigeshurukuang2>.o').removeClass("cur2");
	$('.body_1').removeClass("cur3");
})
// 当点击学生登录时隐藏其他两项，显示学生登录
$('.header>.student').click(function(){
	$('.tfoot>#student').addClass('cur5')
	$('.tfoot>#student').siblings().removeClass("cur5")
	$('.tfoot>#student').removeClass("cur4")
	$('.tfoot>#student').siblings().addClass("cur4")
	
	
})
$('.header>.teacher').click(function(){
	
	$('.tfoot>#teacher').addClass('cur5')
	$('.tfoot>#teacher').siblings().removeClass("cur5")
	$('.tfoot>#teacher').removeClass("cur4")
	$('.tfoot>#teacher').siblings().addClass("cur4")
})
$('.header>.adimn').click(function(){
	$('.tfoot>#administrator').addClass('cur5')
	$('.tfoot>#administrator').siblings().removeClass("cur5")
	$('.tfoot>#administrator').removeClass("cur4")
	$('.tfoot>#administrator').siblings().addClass("cur4")
})

//鼠标放上去
$('.header>.student').mousemove(function(){
	$(".header>.teacher").addClass("cur6")
	$(".header>.adimn").addClass("cur6")
})
$('.header>.teacher').mousemove(function(){
	$(".header>.student").addClass("cur6")
	$(".header>.adimn").addClass("cur6")	
})
$('.header>.adimn').mousemove(function(){
	$(".header>.teacher").addClass("cur6")
	$(".header>.student").addClass("cur6")	
})
//鼠标移开
$('.header>.student').mouseout(function(){
	$(".header>.teacher").removeClass("cur6")
	$(".header>.adimn").removeClass("cur6")
})
$('.header>.teacher').mouseout(function(){
	$(".header>.student").removeClass("cur6")
	$(".header>.adimn").removeClass("cur6")	
})
$('.header>.adimn').mouseout(function(){
	$(".header>.teacher").removeClass("cur6")
	$(".header>.student").removeClass("cur6")	
})
//学生登录ajax请求
	const url='http://127.0.0.1:8080/user/login'
	$('#student>.body_2>div>button').click(function(){
		console.log(1)
		const uname=$('#stu_input1').val()//用户名
		const upwd=$('#stu_input2').val()//密码		
		//获取输入框中的值
		let data = `uname=${uname}&upwd=${upwd}`;
		console.log(data)
		let xhr=new XMLHttpRequest();
		xhr.open("POST",'/user/login');
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
		xhr.onload = () => {
			let jsonObj=JSON.parse(xhr.responseText)
			console.log(jsonObj)

			if(jsonObj.code==200){
				window.location.href='index.html'
			}else if(jsonObj.code==501){
				alert('用户名或密码不正确，请重新登录!')
			}			
			// sessionStorage存储当前登录的用户信息
				let id=jsonObj.result[0].stu_id
				let name=jsonObj.result[0].stu_name
				sessionStorage.setItem('stu_id',id)
				sessionStorage.setItem('stu_name',name)
			////////////////////////////	
		};
		xhr.send(data);
		console.log(data)
		

	})
//讲师登录ajax请求
		const url1='http://127.0.0.1:8080/user/login_tutor'
		$('#teacher>.body_2>div>button').click(function(){
			console.log(1)
			const uname=$('#teacher_input1').val()//用户名
			const upwd=$('#teacher_input2').val()//密码	

			//获取输入框中的值
			let data = `uname=${uname}&upwd=${upwd}`;
			console.log(data)
			let xhr=new XMLHttpRequest();
			xhr.open("POST",'/user/login_tutor');
			xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
			xhr.onload = () => {
				let jsonObj=JSON.parse(xhr.responseText)
				if(jsonObj.code==200){
					window.location.href='teacher.html'	
						// sessionStorage存储当前登录的用户信息
						let name=uname
						sessionStorage.setItem('tutor_name',name)
				}else if(jsonObj.code==501){
					alert('用户名或密码不正确，请重新登录!')
				}

			};
			xhr.send(data);
		})
//管理员登录ajax请求
		const url3='http://127.0.0.1:8080/user/admin_tutor'
		$('#administrator>.body_2>div>button').click(function(){
		console.log(1)
		const uname=$('#admin_input1').val()//用户名
		const upwd=$('#admin_input2').val()//密码
		//获取输入框中的值
		let data = `uname=${uname}&upwd=${upwd}`;
		console.log(data)
		let xhr=new XMLHttpRequest();
		xhr.open("POST",'/user/login_admin');
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
		xhr.onload = () => {
			let jsonObj=JSON.parse(xhr.responseText)
			if(jsonObj.code==200){
					window.location.href='http://localhost:8081/'
				}else if(jsonObj.code==501){
					alert('用户名或密码不正确，请重新登录!')
				}
			};
			xhr.send(data);
		})

